home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / spool.zip / SPOOL.ASM < prev    next >
Assembly Source File  |  1986-02-01  |  39KB  |  1,074 lines

  1.     page    64,132
  2. ;----------------------------------------------------------------------------    
  3. ;    spooler program
  4. ;
  5. ;      modified by craig derouen 6-6-84
  6. ;
  7. ;      Version 2.0 by craig derouen 3-20-85
  8. ;            : change communications interrupt with buffer
  9. ;            : control to ioctl for better,more compatable
  10. ;            : operation. Change additional interrupt to user
  11. ;            : modifiable in case of conflicts.
  12. ;    Version 2.2 by Craig Derouen 4-4-85
  13. ;            : Change status return code so more compat with
  14. ;            : other programs. Add a pause feature. Add reprint
  15. ;            : last page feature.
  16. ;
  17. ; Configuring spooler:
  18. ;
  19. ;    Install the folowing line you CONFIG.SYS file on the boot
  20. ;    disk:
  21. ;              device=spool.dev [/option1] [/option2]
  22. ;
  23. ;     Where option may be the following:
  24. ;        Option 1:  "/1" -"/64" Decimal digit(s) indicating
  25. ;               (k)size of memory to reserve for print 
  26. ;               buffer.
  27. ;
  28. ;        Option 2:  "/L(1,2,3)" or "/C(1,2)". Specifies which
  29. ;               port is buffered, and becomes STANDARD
  30. ;               PRN output. Only one may be specified.
  31. ;               Option "L(1,2,3)" indicates LPT1,LPT2 or
  32. ;               LPT3 respectively. Option "/C(1,2)" indicates
  33. ;               Com1 or Com2 port. 
  34. ;
  35. ;    Thus if the following line is installed:
  36. ;
  37. ;            device = spool.dev /l2 /60
  38. ;
  39. ;    It means spool the PRN output to LPT2, reserve a 60K buffer.
  40. ;
  41. ;    Options are not case sensitive! Options may be installed in
  42. ;    any order. Any other characters are ignored. Default setup
  43. ;    is:
  44. ;        LPT1  and 1K buffer
  45. ;
  46.  
  47. user_int    equ    67h    ; Required additional interrupt. Just change
  48.                 ; it here if conflicts with anything.
  49. formfeed    equ    0ch    ; Form feed char. This is the char the code
  50.                 ; looks for to indicate new page
  51. ;----------------------------------------------------------------------------
  52. cseg    segment para public 'CODE'
  53.     assume    cs:cseg,es:cseg,ds:cseg
  54. ;----------------------------------------------------------------------------
  55. ;            device driver header
  56. ;----------------------------------------------------------------------------
  57. next_dev    dd    -1        ;pointer to next device
  58. attribute    dw      0C000h        ;character type device with ioctl
  59. strategy    dw    dev_strategy    ;pointer to device strategy
  60. interrupt    dw    dev_int        ;pointer to dev_int
  61. dev_name    db    'PRN     '    ;device indentifier
  62. ;-----------------------------------------------------------------------------
  63. ;         f u n c t i o n  t a b l e
  64. ;
  65. ;    this is the table of procedures which are called to service each type
  66. ; of device driver request from ms-dos.
  67. ;-----------------------------------------------------------------------------
  68. funtab        label    byte
  69.         dw    init        ;initialization routine
  70.         dw    exit        ;media check (block only)
  71.         dw    exit        ;build bpb     ""     ""
  72.         dw    ioctl_in    ;ioctl input
  73.         dw    exit        ;input (read)
  74.         dw    nd_input    ;non_destructive input no wait (char only)
  75.         dw    exit        ;input status
  76.         dw    exit        ;input flush
  77.         dw    output        ;output (write)
  78.         dw    output        ;output (write) with verify
  79.         dw    out_stat    ;output status
  80.         dw    out_flush    ;output flush
  81.         dw    ioctl_out    ;ioctl output
  82. ;-----------------------------------------------------------------------------
  83. ;        working variables for bufferring of output
  84. ;-----------------------------------------------------------------------------
  85. port_type    db    0        ;flag specifying lpt or com port - com=0, lpt=1
  86. rh_seg        dd    0        ;request header pointer - segment and offset
  87. data_seg    dw    0        ;data segment for printer data
  88. ending_address    dw    0        ; this is the value past back to dos from the initialization routine
  89. pull_ptr    dw    0        ;points to the current character to output from the buffer
  90. insert_ptr    dw    0        ;points place to insert next character into buffer
  91. buf_size    dw    0        ;size of the printer buffer in characters
  92. port_number    db    0        ;current port number of output port (0,1) if com, (0,1,2) if parallel
  93. move_cnt    dw    0        ;amount of data moved
  94. buf_flg        db    0        ;not zero if buffer full
  95. buff_cnt    dw    0        ;amount of data in the buffer
  96. loop_cnt    dw    0        ;number of times around the loop
  97. priority    dw    100        ;processing priority
  98. pointer_set    db    0        ;non-zero if irq0 vector modifyied
  99. ppause        db    0        ; flag for printer pause
  100. ;-----------------------------------------------------------------------------
  101. ;                device strategy routine
  102. ;
  103. ;    this procedure gets the request header from ms-dos and sets up rh_seg
  104. ; as the pointer used in the buffer driver for manipulation of the request
  105. ; header
  106. ;    entry:    ex:bx --> pointer to request header from ms-dos
  107. ;
  108. ;    exit:    rh_seg --> our internal pointer to request header
  109. ;-----------------------------------------------------------------------------
  110. dev_strategy    proc    far
  111.     mov    word ptr cs:[rh_seg],bx        ;save the request header segment
  112.     mov    word ptr cs:[rh_seg+2],es    ;save the request header offset
  113.     ret
  114. dev_strategy    endp
  115. ;------------------------------------------------------------------------------
  116. ;
  117. ;                device interrupt handler
  118. ;
  119. ;    this procedure is called each time ms-dos calls the driver.  its task
  120. ; is to branch control to the proper procedure to service the request.
  121. ;
  122. ;    this procedure saves all registers, uses rh_seg (pointer to request 
  123. ; header) to get the command number, then uses the command number as an offset
  124. ; into the command table (funtab) to jump to the appropriate procedure to service
  125. ; the request from ms-dos to the driver
  126. ;
  127. ;    entry:    rh_seg --> pointer to request header
  128. ;
  129. ;    exit:    cx --> number of bytes to transfer (read or write)
  130. ;        ex:di --> pointer to data (transfer address)
  131. ;        jump to proper procedure to service request, if valid, or
  132. ;        jump to ioctl_in if invalid command
  133. ;-----------------------------------------------------------------------------
  134. dev_int    proc    far
  135.     push    si
  136.     mov    si,offset funtab    ;point to the start of the function table
  137.     push    ax            ;save all registers onto the stack
  138.     push    bx
  139.     push    cx
  140.     push    dx
  141.     push    di
  142.     push    bp
  143.     push    ds
  144.     push    es
  145.     lds    bx,cs:rh_seg        ;get the request header segment
  146.     mov    cx,[bx+12h]        ;get the amount of data to transfer
  147.     mov    al,[bx+02h]        ;get the command byte
  148.     cbw                ;make 16 bit value
  149.     add    si,ax            ;add into our table value
  150.     add    si,ax            ;do it again
  151.     cmp    al,12            ;is it above the last entry in our table
  152.     ja    exit            ;do null action if so
  153.     les    di,[bx]+14d        ;get pointer to our data
  154.     push    cs            ;make our data segment register
  155.     pop    ds            ;the same as our code segment register
  156.     jmp    word ptr[si]        ;jump to correct action in the table
  157. ;-----------------------------------------------------------------------------
  158. ;            non destructive input routine
  159. ;
  160. ;    this procedure always returns done and busy to ms-dos to indicate that
  161. ; there is no character in the buffer to return.
  162. ;
  163. ;    entry:    rh_seg --> pointer to request header from ms-dos
  164. ;
  165. ;    exit:    rh_seg --> return request header with done and busy set in 
  166. ; status word, no other changes are made to the request header
  167. ;        ah --> 0011 (done and busy bits set)
  168. ;----------------------------------------------------------------------------
  169. nd_input:
  170.     mov    ah,03            ;indicate done and buzy to dos
  171.     jmp    short exit1        ;set our status word
  172. ;----------------------------------------------------------------------------
  173. ;                 dummy return point
  174. ;
  175. ;    this is the return procedure for exiting the driver and returning control
  176. ; to ms-dos.  the status word can be updated to indicate done and number of 
  177. ; characters processed.  the registers which were previously saved are restored
  178. ; prior to exiting.
  179. ;
  180. ;    entry:     ax,cx --> ah and al can be previously set as the status word 
  181. ; should be jmped to.
  182. ;
  183. ;    exit:    ds:bx --> pointer to update request header to return to ms-dos
  184. ;        es,ds,bp,di,dx,cx,bx,ax,si restored in that order
  185. ;-----------------------------------------------------------------------------
  186. exit:    mov    ah,01            ;indicate done for status word
  187.     mov    cx,cs:move_cnt        ;get the amount of data move
  188. exit1:    lds    bx,cs:rh_seg        ;load request header segment
  189.     mov    [bx+03],ax        ;save our exit status word
  190.     mov    [bx+12h],cx        ;save the amount of data read 
  191.     pop    es            ;restore the entry registers from the
  192.     pop    ds            ;stack before exiting
  193.     pop    bp
  194.     pop    di
  195.     pop    dx
  196.     pop    cx
  197.     pop    bx
  198.     pop    ax
  199.     pop    si
  200.     ret
  201. dev_int    endp
  202. ;-----------------------------------------------------------------------------